package view;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;



/**
 * Imager
 * @author Adriano de Albuquerque Batista
 * @author Alfeu Buriti
 * @author Pablo Diego Alencar
 * @author Yuri Cariry Cabral de Melo
 *
 */
public class Imager extends JPanel {

	static final long serialVersionUID  = 1L;
	public static final  int  IDEAL_WIDTH 		= 320; // largura
	public static final  int  IDEAL_HEIGHT 		= 240; // altura
	
	private String 	myImage;

	
	/**
	 * getMyImage
	 * @return myImage
	 */
	public String getMyImage() {
		return myImage;
	}

	/**
	 * setMyImage
	 * @param myImage
	 */
	public void setMyImage(String myImage) {
		this.myImage = myImage;
	}

	
	/**
	 * Imager
	 * @param image
	 */
	public Imager(String image) {
		System.out.println("Inicio do Imager");		
		
		myImage = image;
		JPanel win = new JPanel();
		Frame frame = new Frame();
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		// load image
		BufferedImage currentImage;
		currentImage = new BufferedImage(WIDTH, HEIGHT,
				BufferedImage.TYPE_INT_ARGB);
		Graphics g = currentImage.createGraphics();
		this.paint(g);
		frame.add(win);
		frame.setSize(IDEAL_WIDTH, IDEAL_HEIGHT);
		frame.setVisible(true);
		
		System.out.println("Fim do Imager");
	}

	/**
	 * loadImage
	 * @param name
	 * @return result result
	 */
	private Image loadImage(String name) {
		Image result = null;
		MediaTracker tracker = new MediaTracker(this);
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		result = toolkit.getImage(name);
		tracker.addImage(result, 0);
		try {
			tracker.waitForAll();
		} catch (InterruptedException e) {
			return null;
		}
		return result;
	}

	
	/**
	 * paint
	 * @param g Graphics
	 */
	public void paint(Graphics g) {
		Image seeIt = loadImage("EP0441381.png");  //aomnde?????
		g.drawImage(seeIt, 0, 0, this);
	}
	
}